function mix = loadGMM(filename)

% load a netlab gmm struct from textfile written in Fabrice's clustering format

fileid = fopen(filename, 'rt');
textline = fgetl(fileid);
ncentres = sscanf(textline, '%d', 1);
for i = 1:ncentres
    textline = fgetl(fileid);
    dim = sscanf(textline, '%d', 1);
    tempM = sscanf(textline, ['%d' repmat(' %f', 1, dim)]);
    m(i, :) = tempM(2:end);
    
    textline = fgetl(fileid);
    while isequal(textline, '')    %hack to get around the difference between my saveGMM and Fabrice's
        textline = fgetl(fileid);
    end
    for j = 1:dim
        textline = fgetl(fileid);
        K(j, :, i) = sscanf(textline, repmat('%f', 1, dim));
    end

    textline = fgetl(fileid);
    while isequal(textline, '')    %hack to get around the difference between my saveGMM and Fabrice's
        textline = fgetl(fileid);
    end
    priors(i) = sscanf(textline, '%f', 1);
end

mix = gmm(dim, ncentres, 'full');
mix.priors = priors;
mix.centres = m;
mix.covars = K;
mix.covar_type = 'full';
